package com.xbenben.demoroot.scheduled;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author xbenben
 * 定时任务
 */
@Configuration
@Component
@Slf4j
public class ScheduledDemo {

    @Autowired
    private KafkaTemplate kafkaTemplate;

    public static void main(String[] args) {
        System.out.println("true");
    }

    @Scheduled(cron = "* * * * * 1")
    public void soux() {
        System.out.println("王 小 胖");

    }

    //    @Scheduled(fixedRate = 30)
    public void init() {
        log.info("输出 发送用户日志数据 {}", new Date());
        kafkaTemplate.send("user-log", "11", JSONObject.toJSONString(new Date()));
    }


}
